#include "logger.hpp"

#include <iostream>
#include <fstream>//std::ofstream
#include <ostream>
#include <time.h>

logger::logger(const std::string& file_name) :
	_file_name(file_name)
{ }

void logger::log (logger::log_level_type level, const std::string& log_string)
{
	time_t rawtime;
	time(&rawtime);
    std::cout << level << ": " << log_string << " " << ctime(&rawtime);// << std::endl;
	std::ofstream file;
	file.open (_file_name.c_str());
	file << level << ": " << log_string << " " << ctime(&rawtime);// << std::endl;
	file.close();
}

std::ostream& operator << (std::ostream& stream, const logger::log_level_type& level)
{
	switch (level)
	{
	  case logger::info:
		stream << "info";
		break;
	  case logger::warn:
		stream << "warn";
		break;
	  case logger::error:
		stream << "error";
		break;
	  case logger::debug:
		stream << "debug";
		break;
	  default:
		stream << "Unknown!";
		break;
	}

	return stream;
}
